﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.Core.Metadata;
using Caliburn.PresentationFramework.ApplicationModel;
using Caliburn.PresentationFramework;
using XWord.Fundamental.Domain;
using Microsoft.Practices.ServiceLocation;
using System.Threading;
using XWord.Fundamental.Domain.Model;
using XWord.WPF.ApplicationFramework;
using Luna.WPF.ApplicationFramework;
namespace XWord.GUI.Presenters.Fundamental
{
    [Singleton(typeof(CategoryExplorerPresenter))]
    public class CategoryExplorerPresenter : DockingPresenter
    {
        private readonly IWindowManager _windowManager;
        private readonly IServiceLocator _serviceLocator;
        public CategoryExplorerPresenter(IServiceLocator entityFactory)
        {
            _serviceLocator = entityFactory;
            _windowManager = entityFactory.GetInstance<IWindowManager>();
        }

        private ICategoryModel Model { get; set; }

        protected override void OnInitialize()
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback((object obj) =>
            {
                //Model = _serviceLocator.GetInstance<ICategoryModel>();
                //CategoryList = Model.GetCategoryList().ToObservableCollection();
                //BinaryFormatterHelper.Serialize("CategoryList.data", CategoryList);
                CategoryList=BinaryFormatterHelper.Deserialize<IObservableCollection<Category>>("CategoryList.data");
            }));

            base.OnInitialize();
        }

        private IObservableCollection<Category> _categoryList;
        public IObservableCollection<Category> CategoryList
        {
            get { return _categoryList ?? (_categoryList = new BindableCollection<Category>()); }
            set
            {
                _categoryList = value;
                NotifyOfPropertyChange("CategoryList");
            }
        }

        private Category _selectedItem;
        public Category SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                _selectedItem = value;
                NotifyOfPropertyChange("SelectedItem");
            }
        }
    }
}
